function [z1 z2 z3 z4] = g4

N = 100;
z1 = zeros(N,N);
z2 = zeros(N,N);
z3 = zeros(N,N);
z4 = zeros(N,N);
for i = 1:N,
    for j = 1:N,
        c = (i-1)*(1/N) + eps;
        delta = (j-1)*(1/N) + eps;
        if (c < delta)
            z1(j,i) = 1;
        else
            z2(j,i) = 1;
        end
        if ((delta < c) & (2 >= (c-delta)/delta^2) & (1 <= (c-delta)/delta^2))
            z3(j,i) = 1;
            'hit'
        end

        if (delta <= c & delta^2 >= (c-delta))
            z4(j,i) = 1;
        end
        if (delta >= c & delta^2 >= (delta -c))
            z4(j,i) = 1;
        end
    end
end

%ROOT_FOLDER='/home1/rohithdv/matlab_plots/';
% ROOT_FOLDER='/media/ubuntu_data_dir/rohithdv/MONTHLY_PROGRESS/AUG_2011/forsonet/forsonet/matlab_code/script_used_for_COMNET_submission/';
ROOT_FOLDER='/media/ubuntu_data_dir/rohithdv/MONTHLY_PROGRESS/AUG_2011/forsonet/forsonet/matlab_code/script_for_SocialNetworksSubmission/';

lineProperties = '-xk';
lineWidth = 2;
fontsize = 28;
fontname = 'Helvetica';
fontweight = 'n';
plotType = '';
ciLevel = -1; 
barColor = 'r';

close all;

if 0
% PLOT EXPECTED REGION OF STABILITY

xAxisBound=0:0.01:1;% This is based on the number of rows and columns of the matrix 
yAxisBound=0:0.01:1;% This is based on the number of rows and columns of the matrix 

plotgraph(z1, 'Complete Network', 'std1', xAxisBound, yAxisBound, false);
plotgraph(z2, 'Null Network', 'std2', xAxisBound, yAxisBound, false);
plotgraph(z3, 'Shared Network', 'std3', xAxisBound, yAxisBound, false);
plotgraph(z4, 'Complete Bi-partite Network', 'std4', xAxisBound, yAxisBound, false);

end

% PLOT NETWORK TOPOLOGIES BASED ON SIMULATION RESULTS 
% load socialNetwork.summary_expt3
load socialNetwork.summary_10nodes_expt3
expt=3;
z1 = genmat(socialNetwork(1:400,:));
z2 = genmat(socialNetwork(401:800,:));
z3 = genmat(socialNetwork(801:1200,:));

%%%%%%%%%%%%%% PROCESSING FOR Z1 %%%%%%%%%%%%%%%%%%
b=unique(z1);
size1=size(b);
noOfUniqueElements=size1(1);
count=1;

for j=1:1:noOfUniqueElements
    z1(z1==b(j))=count;
    count = count +1;
end

xAxisBound=0:0.05:1;% This is based on the number of rows and columns of z1
yAxisBound=0:0.05:1;% This is based on the number of rows and columns of z1
colorbarTickPositions=[1.5]; % depends on the number of unique elements - NEED TO BE HARDCODED
colorbarTickLabels={'Null'}; % depends on the number of unique elements  - NEED TO BE HARDCODED
%colorbarTickLabels={'Null','Complete','K-Partite', 'Complete'}; % depends on the number of unique elements  - NEED TO BE HARDCODED
plotgraph(z1, 'density (\gamma) = 0', ['fig1_expt',num2str(expt)] , xAxisBound, yAxisBound, ...
          true, noOfUniqueElements, colorbarTickPositions, colorbarTickLabels);


%%%%%%%%%%%%%% PROCESSING FOR Z2 %%%%%%%%%%%%%%%%%%
b=unique(z2);
size1=size(b);
noOfUniqueElements=size1(1);
count=1;

for j=1:1:noOfUniqueElements
    z2(z2==b(j))=count;
    count = count +1;
end
% swap color 3 with color 4 for legend matching with previous graph
% z2(z2==3)=100;
% z2(z2==4)=3;
% z2(z2==100)=4;

xAxisBound=0:0.05:1;% This is based on the number of rows and columns of z2
yAxisBound=0:0.05:1;% This is based on the number of rows and columns of z2
colorbarTickPositions=[1.4 2.2 3 ]; % depends on the number of unique elements - NEED TO BE HARDCODED
% colorbarTickLabels={'Null','Complete', 'K-Partite','Complete', 'K-Partite' }; % depends on the number of unique elements - NEED TO BE HARDCODED
colorbarTickLabels={'Near-Shared','Near-Complete', 'K-Partite' }; % depends on the number of unique elements - NEED TO BE HARDCODED
plotgraph(z2, 'density (\Gamma) = 0.35', ['fig2_expt',num2str(expt)], xAxisBound, yAxisBound, ...
          true, noOfUniqueElements, colorbarTickPositions, colorbarTickLabels);
      
      
%%%%%%%%%%%%%% PROCESSING FOR Z3 %%%%%%%%%%%%%%%%%%
b=unique(z3);
size1=size(b);
noOfUniqueElements=size1(1);
count=1;

for j=1:1:noOfUniqueElements
    z3(z3==b(j))=count;
    count = count +1;
end
% swap color 3 with color 4 for legend matching with previous graph
% z3(z3==3)=100;
% z3(z3==4)=3;
% z3(z3==100)=4;

xAxisBound=0:0.05:1;% This is based on the number of rows and columns of z3
yAxisBound=0:0.05:1;% This is based on the number of rows and columns of z3
% colorbarTickPositions=[1.4 2.15 2.80 2.95 3.6]; % depends on the number of unique elements - NEED TO BE HARDCODED
% colorbarTickLabels={'Null','Complete', 'K-Partite','Complete', 'K-Partite' }; % depends on the number of unique elements - NEED TO BE HARDCODED
colorbarTickPositions=[1.4 2.2 3 ]; % depends on the number of unique elements - NEED TO BE HARDCODED
colorbarTickLabels={'Near-Shared','Near-Complete', 'K-Partite' }; % depends on the number of unique elements - NEED TO BE HARDCODED


plotgraph(z3, 'density (\gamma) = 0.7', ['fig3_expt',num2str(expt)], xAxisBound, yAxisBound, ...
          true, noOfUniqueElements, colorbarTickPositions, colorbarTickLabels);
      


function figure_handle=plotgraph(matrixToPlot, figureLabel, fileName, ...
                                 xAxisBound, yAxisBound, useColorBar,noOfColors, colorbarTickPositions, colorbarTickLabels)

figure_handle = figure('Name',figureLabel,'NumberTitle','off');
set(gca,'FontName','Helvetica','FontAngle','italic', 'FontSize', fontsize);  

if (useColorBar==0)
    colormap(gray);
    imagesc(xAxisBound, yAxisBound, 1-matrixToPlot);
else
    % colormap(gray);
    % colormap(hsv(6))
    b =     [ 0.0 1.0 1.0;
            0.5 1.0 0.5;
            1.0 1.0 0.0;
            1.0 0.5 0.0;
            1.0 0.0 0.0;
            1.0 0.0 1.0];
    % colormap(b);
    colormap(jet(noOfColors));    
    imagesc(xAxisBound, yAxisBound, matrixToPlot);
    
    hcb = colorbar('Location','EastOutside');
    set(hcb, 'YTickMode','manual');
    set(hcb, 'YTickLabelMode','manual');
    set(hcb,'FontName','Helvetica','FontAngle','italic', 'FontSize', 16);      

    set(hcb, 'YTick',colorbarTickPositions);
    set(hcb , 'YTickLabel', colorbarTickLabels);
end

set(gca,'YDir','normal');
% set (gca, 'XTick', 0:0.2:1);
% set (gca, 'YTick', 0:0.2:1);
title(figureLabel);
h = get(gca, 'title');
set(h, 'FontName', 'Helvetica', 'FontSize', fontsize);

ylabel('benefit (\delta)','fontsize',fontsize,'fontweight',fontweight, 'fontname', fontname);
xlabel('cost (c)','fontsize',fontsize,'fontweight',fontweight, 'fontname', fontname);
 saveas(figure_handle,strcat(ROOT_FOLDER, fileName),'eps'); % -- FOR GRAY
% SCALE IMAGES
% saveas(figure_handle,strcat(ROOT_FOLDER, fileName),'epsc2');
end
end
